﻿using lingopen.Application.BLE;
using lingopen.Application.BLE.Implements;
using lingopen.Entity.BLE;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace lingopen.Foxconn.BLE.TcpServer
{
    class Program
    {
        static IBLETcpAppService ble_tcp_app;
        static void Main(string[] args)
        {
            string cmd = "start";
            //Console.WriteLine("输入:start = 开启监听,stop = 停止监听"); 
            Console.WriteLine("BLE TCP Server 已启动");

            reStart:
            try
            {
                while (cmd != "exit")
                {
                    if (cmd == "start")
                    {


                        if (ble_tcp_app == null) ble_tcp_app = new BLETcpAppService();
                        //启动监听 
                        ble_tcp_app.Start();
                    }
                    else if (cmd == "stop")
                    {
                        if (ble_tcp_app != null)
                        {
                            ble_tcp_app.Stop();
                            Console.WriteLine("BLE TCP Server 已停止");
                        }
                    }
                    else if (cmd == "test")
                    {
                        ble_tcp_app.RunTask();
                    }


                    cmd = Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                ($"Error:" + ex.Message).Log();
                cmd = "stop";
                goto reStart;
            }

        }
    }
}
